package com.imti.mall.product.controller;

import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.pms.pojo.PmsProductFullReduction;
import com.imti.mall.product.service.PmsProductFullReductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/product")
public class PmsProductFullReductionController {
    @Autowired
    PmsProductFullReductionService pmsProductFullReductionService;

    /**
     * 根据商品id查询商品满减表
     * @param id
     * @return
     */
    @RequestMapping("/getPmsProductFullReductionId/{id}")
    public CommonResult getPmsProductFullReductionId(@PathVariable("id") Integer id) {
        List<PmsProductFullReduction> pmsProductFullReductionId = pmsProductFullReductionService.getPmsProductFullReductionId(id);
        if(pmsProductFullReductionId!=null){
            return CommonResult.success(pmsProductFullReductionId);
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据满减表表id修改满减表
     * @param pmsProductFullReduction
     * @return
     */
    @RequestMapping("/upadtePmsProductFullReduction")
    public CommonResult upadtePmsProductFullReduction(PmsProductFullReduction pmsProductFullReduction) {
        Integer integer = pmsProductFullReductionService.upadtePmsProductFullReduction(pmsProductFullReduction);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 查询全部商品满减表价格表
     * @return
     */
    @RequestMapping("/findPmsProductFullReduction")
    public CommonResult findPmsProductFullReduction() {
        List<PmsProductFullReduction> pmsProductFullReduction = pmsProductFullReductionService.findPmsProductFullReduction();
        if(pmsProductFullReduction!=null){
            return CommonResult.success(pmsProductFullReduction);
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据id查询商品满减表格表
     * @return
     */
    @RequestMapping("/findPmsProductFullReductionById/{id}")
    public CommonResult findPmsProductFullReductionById(@PathVariable("id") Integer id) {
        PmsProductFullReduction pmsProductFullReductionById = pmsProductFullReductionService.findPmsProductFullReductionById(id);
        if(pmsProductFullReductionById!=null){
            return CommonResult.success(pmsProductFullReductionById);
        }else {
            return CommonResult.failed("失败");
        }

    }
    /**
     * 添加商品满减表价格表
     * @return
     */
    @RequestMapping("/addPmsProductFullReduction")
    public CommonResult addPmsProductFullReduction(PmsProductFullReduction pmsProductFullReduction) {
        Integer integer = pmsProductFullReductionService.addPmsProductFullReduction(pmsProductFullReduction);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
    /**
     * 根据商品满减表价格表id删除
     * @return
     */
    @RequestMapping("/delPmsProductFullReduction/{id}")
    public CommonResult delPmsProductFullReduction(@PathVariable("id") Integer id) {
        Integer integer = pmsProductFullReductionService.delPmsProductLadder(id);
        if(integer>0){
            return CommonResult.failed("成功");
        }else {
            return CommonResult.failed("失败");
        }

    }
}
